package app.dev.ems.web.wicket.session;

import org.apache.wicket.authroles.authentication.AuthenticatedWebSession;
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
import org.apache.wicket.request.Request;

import app.dev.ems.data.model.impl.User;
import app.dev.ems.web.element.NavigationStatus;
import app.dev.ems.web.wicket.application.EMSApplication;

public class EMSSession extends AuthenticatedWebSession {

	private static final long serialVersionUID = 32168826433844528L;
	
	private User user;
	private NavigationStatus activeHorizontalNavigationStatus;
	private NavigationStatus activeVerticalNavigationStatus;
	
	public EMSSession(Request request) {
		super(request);
		
		setActiveHorizontalNavigationStatus(NavigationStatus.HOME);
		setActiveVerticalNavigationStatus(NavigationStatus.HOME);
	}

	@Override
	public final boolean authenticate(final String username, final String password) {
		if (user == null) {
			user = getEMSApplication().getEmsManeger().getUserManager().findUserByCredential(username, password);
		}

		return user != null;		
	}

	@Override
	public Roles getRoles() {
		return null;
	}
	
	public EMSApplication getEMSApplication() {
		return (EMSApplication) super.getApplication();
	}

	public NavigationStatus getActiveHorizontalNavigationStatus() {
		return activeHorizontalNavigationStatus;
	}

	public void setActiveHorizontalNavigationStatus(NavigationStatus activeHorizontalNavigationStatus) {
		this.activeHorizontalNavigationStatus = activeHorizontalNavigationStatus;
	}

	public NavigationStatus getActiveVerticalNavigationStatus() {
		return activeVerticalNavigationStatus;
	}

	public void setActiveVerticalNavigationStatus(NavigationStatus activeVerticalNavigationStatus) {
		this.activeVerticalNavigationStatus = activeVerticalNavigationStatus;
	}	
	
	public User getUser() {
		return user;
	}	
}
